package com.xr.web.controller.miniprogram;

import com.xr.common.annotation.Log;
import com.xr.common.core.controller.BaseController;
import com.xr.common.core.domain.AjaxResult;
import com.xr.common.core.page.TableDataInfo;
import com.xr.common.enums.BusinessType;
import com.xr.common.utils.poi.ExcelUtil;
import com.xr.miniprogram.domain.MiniProgramDescription;
import com.xr.miniprogram.service.IMiniProgramDescriptionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.List;

/**
 * description: 服务说明模块接口
 *
 * @author: wls
 * @date: 2023/11/9 9:37
 * @version:1.0
 */

@Api("服务说明模块接口")
@RestController
@RequestMapping("/mini/description")
public class MpDescriptionController extends BaseController {

    @Autowired
    private IMiniProgramDescriptionService miniProgramDescriptionService;

    /**
     * 获取服务说明列表
     */
    @ApiOperation("获取服务说明列表")
    @PreAuthorize("@ss.hasPermi('mini:description:list')")
    @GetMapping("/list")
    public TableDataInfo list(MiniProgramDescription miniProgramDescription)
    {
        startPage();
        List<MiniProgramDescription> list = miniProgramDescriptionService.selectMiniProgramDescriptionList(miniProgramDescription);
        return getDataTable(list);
    }

    /**
     * 导出服务说明列表
     */
    @ApiOperation("导出服务说明列表")
    @PreAuthorize("@ss.hasPermi('mini:description:export')")
    @Log(title = "服务说明", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MiniProgramDescription miniProgramDescription)
    {
        List<MiniProgramDescription> list = miniProgramDescriptionService.selectMiniProgramDescriptionList(miniProgramDescription);
        ExcelUtil<MiniProgramDescription> util = new ExcelUtil<MiniProgramDescription>(MiniProgramDescription.class);
        util.exportExcel(response, list, "服务说明数据");
    }

    /**
     * 获取服务说明详细信息
     */
    @ApiOperation("获取服务说明详细信息")
    @PreAuthorize("@ss.hasPermi('mini:description:query')")
    @GetMapping(value = "/{descriptionId}")
    public AjaxResult getInfo(@PathVariable("descriptionId") Long descriptionId)
    {
        return success(miniProgramDescriptionService.selectMiniProgramDescriptionByDescriptionId(descriptionId));
    }

    /**
     * 新增服务说明
     */
    @ApiOperation("新增服务说明")
    @PreAuthorize("@ss.hasPermi('mini:description:add')")
    @Log(title = "服务说明", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MiniProgramDescription miniProgramDescription)
    {
        miniProgramDescription.setCreateBy(getUsername());
        miniProgramDescription.setCreateTime(new Date());
        return toAjax(miniProgramDescriptionService.insertMiniProgramDescription(miniProgramDescription));
    }

    /**
     * 修改服务说明
     */
    @ApiOperation("修改服务说明")
    @PreAuthorize("@ss.hasPermi('mini:description:edit')")
    @Log(title = "服务说明", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MiniProgramDescription miniProgramDescription)
    {
        miniProgramDescription.setUpdateBy(getUsername());
        miniProgramDescription.setUpdateTime(new Date());
        return toAjax(miniProgramDescriptionService.updateMiniProgramDescription(miniProgramDescription));
    }

    /**
     * 删除服务说明
     */
    @ApiOperation("删除服务说明[组]")
    @PreAuthorize("@ss.hasPermi('mini:description:remove')")
    @Log(title = "服务说明", businessType = BusinessType.DELETE)
    @DeleteMapping("/{descriptionIds}")
    public AjaxResult remove(@PathVariable Long[] descriptionIds)
    {
        return toAjax(miniProgramDescriptionService.deleteMiniProgramDescriptionByDescriptionIds(descriptionIds));
    }
}
